{% extends "shop/base.html" %}
{% load static %}
{% block title %}Your shopping cart{% endblock %}
{% block content %}
<h1>Your shopping cart</h1>
<table class="cart">
    <thead>
        <tr>
            <th>Image</th>
            <th>Product</th>
            <th>Quantity</th>
            <th>Remove</th>
            <th>Unit price</th>
            <th>Price</th>
        </tr>
    </thead>
    <tbody>
        {% for item in user_cart %}
        {% with product=item.product %}
        <tr>
            <td>
                <a href="{{ product.get_absolute_url }}">
                    <img src="{% if product.image %}{{ product.image.url }}
                              {% else %}{% static "img/no_image.png" %}{% endif %}">
                </a>
            </td>
            <td>{{ product.name }}</td>
            <td>
                <form action="{% url 'cart:add_product' slug=product.slug %}" method="post">
                    {% csrf_token %}
                    {{ item.update_cart.quantity }}
                    {{ item.update_cart.update_cart }}
                    <input type="submit" value="Update">
                </form>
            </td>
            <td><a href="{% url 'cart:remove_product' slug=product.slug %}">Remove</a></td>
            <td class="num">${{ item.price }}</td>
            <td class="num">${{ item.total_price }}</td>
        </tr>
        {% endwith %}
        {% endfor %}
        <tr class="total">
            <td>Total</td>
            <td colspan="4"></td>
            <td class="num">${{ user_cart.get_total_price }}</td>
        </tr>
    </tbody>
</table>
<p class="text-right">
<a href="{% url 'shop:list_products' %}" class="button light">Continue shopping</a>
<a class="button" href="{% url 'cart:clear_cart' %}">Clear</a>
<a href="#" class="button">Checkout</a>
</p>
{% endblock %}
